package com.ofek.eventos.db.datatypes.helptypes;

import java.io.Serializable;

import com.ofek.applicationbase.forms.FormField;
import com.ofek.base.db.DataField;
import com.ofek.base.db.DataTypeClass;
@DataTypeClass(defineKeys=" FOREIGN KEY (ts,tsOwner,eid,eidOwner) REFERENCES EventInfo(ts,tsOwner,eid,eidOwner) ON DELETE CASCADE")
public class ScheduleFieldInEvent implements Serializable {
	@DataField(isKey = true)
	@FormField
	public long eid;
	@DataField(isKey = true)
	@FormField
	public int eidOwner;
	@DataField(isKey = true)
	@FormField
	public long ts;
	@DataField(isKey = true)
	@FormField
	public int tsOwner;
	@DataField(isKey = true, references = FieldInfo.class, referenceField = "fid")
	@FormField
	public long fid;
	@DataField(isKey = true)
	@FormField
	public long startTime = System.currentTimeMillis();
	public final static long INDEFENITE = -1;
	@DataField
	@FormField
	public long endTime = INDEFENITE;
	public final static long NO_REPEAT = -1;
	@DataField
	@FormField
	public long repeatEvery = NO_REPEAT;
	@DataField
	@FormField
	public long repeatUntil = INDEFENITE;
	@Override
	public String toString() {
		return "eid "+eid +",fid "
				+fid +",repeatEvery "+ repeatEvery+ ",repeatUntil " +repeatUntil;
	}
	public ScheduleFieldInEvent(final long eid, final long fid, final long startTime,
			final long endTime, final long repeatEvery, final long repeatUntil) {
		this.eid = eid;
		this.fid = fid;
		this.startTime = startTime;
		this.endTime = endTime;
		this.repeatEvery = repeatEvery;
		this.repeatUntil = repeatUntil;
	}
	public ScheduleFieldInEvent() {
		// TODO Auto-generated constructor stub
	}
	public ScheduleFieldInEvent(final long fid) {
		this.fid = fid;
	}
	public boolean isBetween(final long start, final long end) {
		if ( startTime>=start ) {
			if ( endTime==INDEFENITE || endTime<=end  ) return true;
		}
		return false;
	}
}
